package cn.micro.eye;

import cn.micro.eye.commons.utils.ClassUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.reflect.Method;
import java.util.Set;

public class Demo {

    public static void main(String[] args) {
        int k = 1;
        Set<Class<?>> classes = ClassUtils.getClasses("cn.micro.eye.web");
        for (Class<?> clz : classes) {
            RequestMapping classMP = clz.getAnnotation(RequestMapping.class);
            String classPath = "/"+classMP.value()[0];
            Method[] methods = clz.getDeclaredMethods();
            for (Method method : methods) {
                RequestMapping mp = method.getAnnotation(RequestMapping.class);
                if (mp != null) {
                    RequestMethod[] requestMethods = mp.method();
                    String methodMP = classPath;
                    if (mp.value().length == 1) {
                        methodMP += "/" + mp.value()[0];
                    }
                    methodMP += "/**";
//                    System.out.println("insert into `permission` " +
//                            "( `url`, `created_by`, `deleted`, `updated_by`, `sort`, `method`) values " +
//                            "('" + methodMP + "', '1', '0', '1', '" + (k++) + "','" + requestMethods[0] + "');");
                    System.out.println("insert into `eye`.`role_permission` ( `role_id`, `permission_id`, `created_at`, `created_by`, `updated_at`, `updated_by`, `deleted`, `remarks`) values ( '5', '"+(k++)+"', null, null, null, null, '0', null);");
                }
            }
        }
    }

}
